package com.lishe.lishe.lishe.module.me.pickerView.adapter;

/**
 * Created by zhcasecom on 2017/9/27.
 */

public class StringWheelAdapter implements WheelAdapter {

    /**
     * The default min value
     */
    public static final String DEFAULT_MAX_VALUE = "9";

    /**
     * The default max value
     */
    private static final String DEFAULT_MIN_VALUE = "0";

    // Values
    private String minValue;
    private String maxValue;

    /**
     * Default constructor
     */
    public StringWheelAdapter() {
        this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE);
    }

    /**
     * Constructor
     *
     * @param minValue the wheel min value
     * @param maxValue the wheel max value
     */
    public StringWheelAdapter(String minValue, String maxValue) {
        this.minValue = minValue;
        this.maxValue = maxValue;
    }

    @Override
    public Object getItem(int index) {
        if (index >= 0 && index < getItemsCount()) {
            String value = minValue + index;
            return value;
        }
        return 0;
    }

    @Override
    public int getItemsCount() {
        return Integer.parseInt(maxValue.substring(0, maxValue.length())) - Integer.parseInt(minValue.substring(0, minValue.length())) + 1;
    }

    @Override
    public int indexOf(Object o) {
        return (int) o - Integer.parseInt(minValue.substring(0, minValue.length()));
    }
}
